package com.xy.p2p.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;

import com.xy.p2p.model.Tfinanceinfo;
import com.xy.p2p.model.Tmember;
import com.xy.p2p.model.Tmemberassetaccount;
import com.xy.p2p.model.Ttenderrecord;
import com.xy.p2p.service.SchedulerService;
import com.xy.p2p.service.TfinanceinfoService;
import com.xy.p2p.service.TmemberService;
import com.xy.p2p.service.TmemberassetaccountService;

public class SchedulerServiceImpl implements SchedulerService {
	
	@Autowired
	private TfinanceinfoService tfinanceinfoService;
	@Autowired
	private TmemberService tmemberService;
	@Autowired
	private TmemberassetaccountService tmemberassetaccountService;
	
	@Override
	public void countFee() {
		System.out.println("+++++++++执行每日任务++++++++++");
		Map<String , Object> map = new HashMap<String, Object>();
		map.put("targettype", 8);
		map.put("status", 2);
		List<Tfinanceinfo> tList = tfinanceinfoService.getTfinanceinfo(map);
		int d = 0;
		for (Tfinanceinfo t : tList) {
			tfinanceinfoService.YEDPay(t);
			d++;
		}
		System.out.println("+++++++++执行每日任务共"+tList.size()+"条余额贷记录++++++共还款"+d+"人+++++");
	}

	@Override
	public void countFee2() {
		Double assets = 0.0;
		List<Tmember> ltmember = tmemberService.getAll();
		Set<Tmemberassetaccount> tmemberassetaccount = null;
		Set<Ttenderrecord> ttenderrecords = null;
		for (Tmember t : ltmember) {
			tmemberassetaccount = t.getTmemberassetaccounts();
			assets = tmemberassetaccountService.getTotalAsset(t);
			for(Tmemberassetaccount tt : tmemberassetaccount){
				if(tt.getBalance()!=0||tt.getAmountfrozen()!=0||assets!=0)
					tmemberassetaccountService.billing(t.getMemberid());
			}
		}
		System.out.println("+++++++++执行每月任务+++++++++");
	}
}
